package com.tuanzi.loan.business.repository.member.impl;

import com.tuanzi.loan.business.repository.member.custom.LoanMemberPriceCustomRepository;
import com.tuanzi.loan.core.repository.JOOQBaseRepository;
import com.tuanzi.loan.vo.request.member.LoanMemberPriceRequest;
import com.tuanzi.loan.vo.response.member.LoanMemberPriceResponse;
import org.jooq.impl.TableImpl;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import static com.tuanzi.loan.generated.jooq.loan.tables.LoanMemberPrice.LOAN_MEMBER_PRICE;

/**
 * User: liangZongXi
 * Create time: 11:12 2019/4/3
 * Description:
 */

@Repository
public class LoanMemberPriceRepositoryImpl extends JOOQBaseRepository implements LoanMemberPriceCustomRepository {

    @Override
    public Page<LoanMemberPriceResponse> list(LoanMemberPriceRequest searchRequest, Pageable pageable) {
        fields(LOAN_MEMBER_PRICE.fields());
        eq(LOAN_MEMBER_PRICE.PRODUCT_ID,searchRequest.getProductId());
        return search(pageable, record -> {
            LoanMemberPriceResponse loanMemberPriceResponse = new LoanMemberPriceResponse();
            loanMemberPriceResponse.setId(record.get(LOAN_MEMBER_PRICE.ID));
            loanMemberPriceResponse.setPrice(record.get(LOAN_MEMBER_PRICE.PRICE));
            loanMemberPriceResponse.setProductId(record.get(LOAN_MEMBER_PRICE.PRODUCT_ID));
            return loanMemberPriceResponse;
        });
    }

    @Override
    protected TableImpl getTable() {
        return LOAN_MEMBER_PRICE;
    }
}
